﻿package com.projects.xenia.journals_activities;import java.text.SimpleDateFormat;

import android.app.Activity;
import android.content.Intent;
import android.widget.Toast;

import com.projects.xenia.MainReturnActivity;
import com.projects.xenia.R;
import com.projects.xenia.documents_activities.Activity_Blank;
import com.projects.xenia.documents_classes.Documents_Blank;
import com.projects.xenia.documents_classes.Documents_Visit;
import com.projects.xenia.global_modules.MainGlobalModule;

public class Activity_Journal_Blanks extends JournalActivity {

	@Override
	public void SetIconAndDescr() {
		
		head_ico.setImageResource(R.drawable.st_info);
		head_text.setText("Анкеты");
		
	}
	
	@Override
	public void GetJournalCursor () {		
	
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss");		
		String BlankJournalStartDateValueString = sdf.format(JournalStartDateValue);
		String BlankJournalStopDateValueString = sdf.format(JournalStopDateValue);
			
		JournalCursor = MainGlobalModule.DBE.rawQuery("select a.id,a.docnum,date(a.date_create) as date_create ,a.state,a.customers_id,0,b.descr,b.outletdescr,b.outletadress from xdoc_blanks_h a left outer join xref_customers b on a.customers_id = b.id where date(a.date_create) between date(?) and date(?) order by date(a.date_create),a.docnum", new String []{BlankJournalStartDateValueString,BlankJournalStopDateValueString});		
				
		
	}        

	@Override
	public void StartDocumentsDetailsJournalActivity() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void CreateOpenDocument() {
		
		if (Journ_Customer.getTag()!=null) {
			Documents_Visit DocVisit = new Documents_Visit ();
			if (DocVisit.CheckNewVisitsExistsByCustomerId(String.valueOf(Journ_Customer.getTag()))) {
				Toast.makeText(this, "Нелья создать документ вне визита !!!", Toast.LENGTH_SHORT).show();
				return;
			}		
		}
		
		

		if (Journ_Customer.getTag()!=null) {
			Documents_Visit DocVisit = new Documents_Visit ();
			if (DocVisit.CheckNewVisitsExistsByCustomerId(String.valueOf(Journ_Customer.getTag()))) {
				Toast.makeText(this, "Нельзя создать документ вне визита !!!", Toast.LENGTH_SHORT).show();
				return;
			}		
		}

    	Intent DocumentActivity = new Intent ();    	
    	DocumentActivity.setClass(Ctx, Activity_Blank.class);
    	DocumentActivity.putExtra("CustomerId", Journ_Customer.getTag()==null?null:String.valueOf(Journ_Customer.getTag()));    	
    	((Activity)Ctx).startActivityForResult(DocumentActivity, 0);
    	
	}

	@Override
	public void OpenDocument() {
		
		Intent DocumentActivity = new Intent ();    	
    	DocumentActivity.setClass(Ctx, Activity_Blank.class);
    	DocumentActivity.putExtra("DocId", id);    	
    	((Activity)Ctx).startActivityForResult(DocumentActivity, 0);
    	
	}

	@Override
	public void DeleteDocument() {
		
		Documents_Blank Doc = new Documents_Blank ();
		Doc.OpenDoc(id);
		Doc.DeleteDoc();
		RefreshList();
		
	}

	@Override
	public void JournIcoEvents() {
		// TODO Auto-generated method stub
		
	}
	
}
